package part12_命令模式_一个app控制所有家电;

/**
 * @ClassName: Client
 * @Author: AllenSun
 * @Date: 2020/3/5 0:09
 */
public class Client {
    public static void main(String[] args) {
        //使用命令模式，完成通过遥控器，对电灯的操作
        //创建一个电灯对象
        LightReceiver lightReceiver=new LightReceiver();
        //创建电灯相关的开关命令
        LightOnCommand lightOnCommand=new LightOnCommand(lightReceiver);
        LightOffCommand lightOffCommand=new LightOffCommand(lightReceiver);

        //创建一个电灯对象
        TvReceiver tvReceiver=new TvReceiver();
        //创建电灯相关的开关命令
        TvOnCommand tvOnCommand=new TvOnCommand(tvReceiver);
        TvOffCommand tvOffCommand=new TvOffCommand(tvReceiver);

        //需要一个遥控器
        RemoteController remoteController=new RemoteController();
        //给遥控器设置相关的命令，no=0是电灯的开关操作
        remoteController.setCommand(0,lightOnCommand,lightOffCommand);
        remoteController.setCommand(1,tvOnCommand,tvOffCommand);

        System.out.println("-----按下灯开的按钮-----");
        remoteController.onbuttonWasPushed(0);
        System.out.println("-----按下灯关的按钮-----");
        remoteController.offbuttonWasPushed(0);
        System.out.println("-----按下撤销的按钮-----");
        remoteController.undobuttonWasPushed();

        System.out.println("-----按下电视开的按钮-----");
        remoteController.onbuttonWasPushed(1);
        System.out.println("-----按下电视关的按钮-----");
        remoteController.offbuttonWasPushed(1);
        System.out.println("-----按下撤销的按钮-----");
        remoteController.undobuttonWasPushed();

    }
}
